package com.todod.base.module.base.dal.mysql.standards;

import java.util.*;

import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.todod.base.framework.mybatis.core.mapper.BaseMapperX;
import com.todod.base.module.base.dal.dataobject.standards.StandardsDO;
import org.apache.ibatis.annotations.Mapper;
import com.todod.base.module.base.controller.admin.standards.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 协议库 Mapper
 *
 * @author 平台
 */
@Mapper
public interface StandardsMapper extends BaseMapperX<StandardsDO> {

    default PageResult<StandardsDO> selectPage(StandardsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StandardsDO>()
                .likeIfPresent(StandardsDO::getFieldName, reqVO.getFieldName())
                .likeIfPresent(StandardsDO::getChMean, reqVO.getChMean())
                .eqIfPresent(StandardsDO::getCalculMethod, reqVO.getCalculMethod())
                .eqIfPresent(StandardsDO::getWitsCode, reqVO.getWitsCode())
                .eqIfPresent(StandardsDO::getUnit, reqVO.getUnit())
                .eqIfPresent(StandardsDO::getDeviceType, reqVO.getDeviceType())
                .eqIfPresent(StandardsDO::getDeviceMode, reqVO.getDeviceMode())
                .eqIfPresent(StandardsDO::getState, reqVO.getState())
                .betweenIfPresent(StandardsDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StandardsDO::getId));
    }

    @Select("SELECT COUNT(*) FROM base_standards WHERE device_type = #{deviceType} AND device_mode = #{deviceMode} AND serial_number  = #{serialNumber} AND field_name = #{fieldName} AND deleted = 0")
    public int isExist(StandardsDO standardsDO);

}